<template>
  <p-modal
    :title="title"
    :width="width"
    :visible="visible"
    :confirmLoading="confirmLoading"
    @ok="handleOk"
    @cancel="handleCancel"
    cancelText="关闭">
    <p-spin :spinning="confirmLoading">
      <p-form :form="form">
        <p-row>
		  <p-col  :span="24">
			<p-form-item label="员工编号" :labelCol="labelCol" :wrapperCol="wrapperCol">
				<f-popup
						contextPath="mes-manpower"
						v-decorator="['empno', validatorRules.empno]"
						:trigger-change="true"
						org-fields="empno,empname,id,empno,empname,id"
						dest-fields="empid,empname,empid,empid,,id"
						code="mes_hr_employeeinfo"
						@callback="popupCallback"/>
			</p-form-item>
		  </p-col>
		  <p-col  :span="24">
			<p-form-item label="员工姓名" :labelCol="labelCol" :wrapperCol="wrapperCol">
				<p-input readOnly v-decorator="[ 'empname', validatorRules.empname]" placeholder="请输入员工姓名"></p-input>
			</p-form-item>
		  </p-col>
		  <p-col  :span="24">
			<p-form-item label="车间" :labelCol="labelCol" :wrapperCol="wrapperCol">
				<p-input readOnly v-decorator="[ 'workroomname', validatorRules.workroomname]" placeholder="请输入车间"></p-input>
			</p-form-item>
		  </p-col>
		  <p-col  :span="24">
			<p-form-item label="车间编码" :labelCol="labelCol" :wrapperCol="wrapperCol">
				<p-input readOnly v-decorator="[ 'workroomno', validatorRules.workroomno]" placeholder="请输入车间编码"></p-input>
			</p-form-item>
		  </p-col>
		  <p-col  :span="24">
			<p-form-item label="线体" :labelCol="labelCol" :wrapperCol="wrapperCol">
				<p-input readOnly v-decorator="[ 'linename', validatorRules.linename]" placeholder="请输入线体"></p-input>
			</p-form-item>
		  </p-col>
		  <p-col  :span="24">
			<p-form-item label="线体编码" :labelCol="labelCol" :wrapperCol="wrapperCol">
				<f-popup
						contextPath="basic-business"
						v-decorator="['lineno', validatorRules.lineno]"
						:trigger-change="true"
						org-fields="lineid,lineno,linename,workroomid,workroomno,workroomname"
						dest-fields="lineid,lineno,linename,workroomid,workroomno,workroomname"
						code="line_select"
						@callback="popupCallback"/>
			</p-form-item>
		  </p-col>
		  <p-col  :span="24">
			<p-form-item label="班组" :labelCol="labelCol" :wrapperCol="wrapperCol">
				<p-input readOnly v-decorator="[ 'classname', validatorRules.classname]" placeholder="请输入班组"></p-input>
			</p-form-item>
		  </p-col>
		  <p-col  :span="24">
			<p-form-item label="班组编号" :labelCol="labelCol" :wrapperCol="wrapperCol">
				<f-popup
						contextPath="basic-business"
						v-decorator="['classno', validatorRules.classno]"
						:trigger-change="true"
						org-fields="classno,classname"
						dest-fields="classno,classname"
						code="mes_hr_q_classinfo"
						@callback="popupCallback"/>
			</p-form-item>
		  </p-col>
		  <p-col  :span="24">
			<p-form-item label="技能" :labelCol="labelCol" :wrapperCol="wrapperCol">
				<p-input  v-decorator="[ 'skillname', validatorRules.skillname]" placeholder="请输入技能"></p-input>
			</p-form-item>
		  </p-col>
		  <p-col  :span="24">
			<p-form-item label="技能编号" :labelCol="labelCol" :wrapperCol="wrapperCol">
				<f-popup
						contextPath="mes-manpower"
						v-decorator="['skillno', validatorRules.skillno]"
						:trigger-change="true"
						org-fields="id,skill_code,skill_name"
						dest-fields="skillid,skillno,skillname"
						code="mes_hr_q_skill"
						@callback="popupCallback"/>
			</p-form-item>
		  </p-col>
		  <p-col  :span="24">
			<p-form-item label="计划开始时间" :labelCol="labelCol" :wrapperCol="wrapperCol">
				<j-date    placeholder="请选择计划开始时间" v-decorator="[ 'planStartTime', validatorRules.planStartTime]" :trigger-change="true" style="width: 100%"/>
			</p-form-item>
		  </p-col>
		  <p-col  :span="24">
			<p-form-item label="计划结束时间" :labelCol="labelCol" :wrapperCol="wrapperCol">
				<j-date    placeholder="请选择计划结束时间" v-decorator="[ 'planEndTime', validatorRules.planEndTime]" :trigger-change="true" style="width: 100%"/>
			</p-form-item>
		  </p-col>
		  <p-col  :span="24">
			<p-form-item label="通识培训" :labelCol="labelCol" :wrapperCol="wrapperCol">
				<p-input-number   v-decorator="[ 'liberalTrain', validatorRules.liberalTrain]" placeholder="请输入通识培训" style="width: 100%"/>
			</p-form-item>
		  </p-col>
		  <p-col  :span="24">
			<p-form-item label="技能培训" :labelCol="labelCol" :wrapperCol="wrapperCol">
				<p-input-number   v-decorator="[ 'skillTrain', validatorRules.skillTrain]" placeholder="请输入技能培训" style="width: 100%"/>
			</p-form-item>
		  </p-col>
		  <p-col  :span="24">
			<p-form-item label="线长确认" :labelCol="labelCol" :wrapperCol="wrapperCol">
				<p-input-number   v-decorator="[ 'lineleaderConfirm', validatorRules.lineleaderConfirm]" placeholder="请输入线长确认" style="width: 100%"/>
			</p-form-item>
		  </p-col>
		  <p-col  :span="24">
			<p-form-item label="见习考核" :labelCol="labelCol" :wrapperCol="wrapperCol">
				<p-input-number   v-decorator="[ 'traineeAsm', validatorRules.traineeAsm]" placeholder="请输入见习考核" style="width: 100%"/>
			</p-form-item>
		  </p-col>
		  <p-col  :span="24">
			<p-form-item label="上岗证日期" :labelCol="labelCol" :wrapperCol="wrapperCol">
				<j-date    placeholder="请选择上岗证日期" v-decorator="[ 'workpcardDate', validatorRules.workpcardDate]" :trigger-change="true" style="width: 100%"/>
			</p-form-item>
		  </p-col>
		  <p-col  :span="24">
			<p-form-item label="复核" :labelCol="labelCol" :wrapperCol="wrapperCol">
				<p-input-number   v-decorator="[ 'review', validatorRules.review]" placeholder="请输入复核" style="width: 100%"/>
			</p-form-item>
		  </p-col>
		  <p-col  :span="24">
			<p-form-item label="培训次数" :labelCol="labelCol" :wrapperCol="wrapperCol">
				<p-input-number   v-decorator="[ 'trainTimes', validatorRules.trainTimes]" placeholder="请输入培训次数" style="width: 100%"/>
			</p-form-item>
		  </p-col>
		  <p-col  :span="24">
			<p-form-item label="结果" :labelCol="labelCol" :wrapperCol="wrapperCol">
				<p-input-number   v-decorator="[ 'result', validatorRules.result]" placeholder="请输入结果" style="width: 100%"/>
			</p-form-item>
		  </p-col>
		  <p-col  :span="24">
			<p-form-item label="处置" :labelCol="labelCol" :wrapperCol="wrapperCol">
				<p-input-number   v-decorator="[ 'dispose', validatorRules.dispose]" placeholder="请输入处置" style="width: 100%"/>
			</p-form-item>
		  </p-col>
		  <p-col  :span="24">
			<p-form-item label="备注" :labelCol="labelCol" :wrapperCol="wrapperCol">
				<p-input  v-decorator="[ 'remark', validatorRules.remark]" placeholder="请输入备注"></p-input>
			</p-form-item>
		  </p-col>
        </p-row>


      </p-form>
    </p-spin>
  </p-modal>
</template>

<script>

  import { httpAction } from '@/api/manage'
  import { SubmitOnchangMixin } from '@/mixins/SubmitOnchangMixin'
  import pick from 'lodash.pick'
  import JDate from '@/components/jeecg/JDate'

  export default {
    name: "MesHrMtplanDetailModal",
	mixins: [SubmitOnchangMixin],
    components: {
      JDate,
    },
    props:{
      mainId:{
        type:String,
        required:false,
        default:''
      }
    },
    data () {
      return {
        form: this.$form.createForm(this),
        title: '操作',
        width: 800,
        visible: false,
        model: {},
        labelCol: {
          xs: { span: 24 },
          sm: { span: 5 },
        },
        wrapperCol: {
          xs: { span: 24 },
          sm: { span: 16 },
        },

        confirmLoading: false,
        validatorRules:{
        empno: {},
        empname: {},
        workroomname: {},
        workroomno: {},
        linename: {},
        lineno: {rules: [{ required: true, message: '请输入线体编码!' }]},
        classname: {},
        classno: {rules: [{ required: true, message: '请输入班组编号!' }]},
        skillname: {},
        skillno: {rules: [{ required: true, message: '请输入技能编号!' }]},
        planStartTime: {rules: [{ required: true, message: '请输入计划开始时间!' }]},
        planEndTime: {rules: [{ required: true, message: '请输入计划结束时间!' }]},
        liberalTrain: {},
        skillTrain: {},
        lineleaderConfirm: {},
        traineeAsm: {},
        workpcardDate: {},
        review: {},
        trainTimes: {},
        result: {},
        dispose: {},
        remark: {},
        },
        url: {
          add: '/mes-manpower/auto/mesHrMemberTrainPlan/addMesHrMtplanDetail',
          edit: '/mes-manpower/auto/mesHrMemberTrainPlan/editMesHrMtplanDetail',
        }

      }
    },
    created () {
    },
    methods: {
      add () {
        this.edit({});
      },
      edit (record) {
        this.form.resetFields();
        this.model = Object.assign({}, record);
        this.visible = true;
        this.$nextTick(() => {
          this.form.setFieldsValue(pick(this.model,'timestamp','companyId','factoryId','clientId','substituteId','flag','emptype','empid','empno','empname','workroomname','workroomid','workroomno','linename','lineid','lineno','classname','classno','classid','skillname','skillno','skillid','planStartTime','planEndTime','liberalTrain','skillTrain','lineleaderConfirm','traineeAsm','workpcardDate','review','trainTimes','result','dispose','status','trainPlanId','totalScore','checkDate','lineleader','ratio','quality','resultCheck','assessDate','checkReport','version','createBy','createTime','updateBy','updateTime','remark'))
        })
      },
      close () {
        this.$emit('close');
        this.visible = false;
      },
		handleOk () {
			const that = this;
			// 触发表单验证
			this.form.validateFields((err, values) => {
			  if (!err) {
				  that.confirmLoading = true;
				  let httpurl = '';
				  let method = '';
				  let formData = Object.assign(this.model, values);
				  this.formData = Object.assign(this.model, values);
                  formData['trainPlanId'] = this.mainId
                  this.formData['trainPlanId'] = this.mainId
				  //新增触发
				  if(!this.model.id){
					httpurl+=this.url.add;
					method = 'post';
					if(this.EnhanceJS.afterAdd){
					  //新增之前
					  let Obj = eval(this.EnhanceJS.afterAdd)
					  new Obj(this)
					}else{
					  console.log("表单提交数据",formData)
					  that.modalFrom(httpurl,formData,method)
					}
				  }else{
					//编辑触发
					httpurl+=this.url.edit;
					method = 'put';
					if(this.EnhanceJS.afterEdit){
					 //编辑之前
					  let Obj = eval(this.EnhanceJS.afterEdit)
					  new Obj(this)
					}else{
					  console.log("表单提交数据",formData)
					  that.modalFrom(httpurl,formData,method)
					}
				  }
			  }

			})
		},
      handleCancel () {
        this.close()
      },
      popupCallback(row){
        this.form.setFieldsValue(pick(row,'timestamp','companyId','factoryId','clientId','substituteId','flag','emptype','empid','empno','empname','workroomname','workroomid','workroomno','linename','lineid','lineno','classname','classno','classid','skillname','skillno','skillid','planStartTime','planEndTime','liberalTrain','skillTrain','lineleaderConfirm','traineeAsm','workpcardDate','review','trainTimes','result','dispose','status','trainPlanId','totalScore','checkDate','lineleader','ratio','quality','resultCheck','assessDate','checkReport','version','createBy','createTime','updateBy','updateTime','remark'))
      },


    }
  }
</script>
